package com.zrrd.yt.product.controller;

import com.zrrd.yt.common.result.Result;
import com.zrrd.yt.model.product.BaseCategory1;
import com.zrrd.yt.model.product.BaseCategory2;
import com.zrrd.yt.model.product.BaseCategory3;
import com.zrrd.yt.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author HongyueYang
 */
@RestController
@RequestMapping("/admin/product")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    //获取一级分类
    @GetMapping("/getCategory1")
    public Result<List<BaseCategory1>> getCategory1(){
        return Result.ok(categoryService.list(null));
    }

    //获取二级分类
    @GetMapping("/getCategory2/{category1Id}")
    public Result<List<BaseCategory2>> getCategory2(@PathVariable("category1Id") Long category1Id){
        return Result.ok(categoryService.getCategory2List(category1Id));
    }

    //获取三级分类
    @GetMapping("/getCategory3/{category2Id}")
    public Result<List<BaseCategory3>> getCategory3(@PathVariable("category2Id") Long category2Id){
        return Result.ok(categoryService.getCategory3List(category2Id));
    }
}
